//
//  HTAddToWishListAlertView.swift
//  MagaCore
//
//  Created by 罗林轩 on 2024/8/28.
//  Copyright © 2024 HT. All rights reserved.
//

import SwiftUI

struct HTAddToWishListAlertView: View {
    /// 显示的状态
    var var_showAddToWishListAlert : Bool = false
    /// 是否隐藏
    @State private  var _isHidden : Bool = true
    
    init(var_showAddToWishListAlert: Bool) {
        self.var_showAddToWishListAlert = var_showAddToWishListAlert
    }
    
    var body: some View {
        VStack {
            Spacer()
            HStack {
                Spacer()
                Image(var_showAddToWishListAlert ? "Vector" : "ad_close_white")
                Text(var_showAddToWishListAlert ? "Added To My Watchlist" : "Remove From My WatchList")
                    .ht_commonTextStyle(color: .white, fontSize: 17, weight: .regular)
                Spacer()
            }
            .padding(.horizontal,20)
            .padding(.vertical,10)
            .onChange(of: var_showAddToWishListAlert, perform: { newValue in
                self.hide(seconds: 2)
            })
            .background(Color(hex: "#4F40BD"))
            .opacity(_isHidden ? 0 : 1)
            .cornerRadius(18, corners: .allCorners)
            .frame(width: var_screenWidth * 0.8)
            .offset(x:var_screenWidth * 0.1,y:-200)
        }
    }
    
    func hide(seconds: Double) {
        withAnimation(.easeInOut(duration: 0.5)){
            self._isHidden = false
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
            withAnimation(.easeInOut(duration: 0.5)){
                self._isHidden = true
            }
        }
    }
}

#Preview {
    HTAddToWishListAlertView(var_showAddToWishListAlert: true)
}
